package inventoryservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/BeanUtils"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type InventoryAssetReturnEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInventoryAssetReturnEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InventoryAssetReturnEditLogic {
	return &InventoryAssetReturnEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// InventoryAssetReturnEdit 更新资产退库表
func (l *InventoryAssetReturnEditLogic) InventoryAssetReturnEdit(in *property_service.InventoryAssetReturn) (*property_service.Response, error) {
	// 获取资产退库表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).InventoryAssetReturn
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、StockID、UpdatedAt、CreatedAt
	if _, err := do.UpdateColumns(&model.InventoryAssetReturn{
		ReturnCode:       in.ReturnCode,                          // 退库单号
		ReturnDate:       BeanUtils.GetDateFormat(in.ReturnDate), // 退库日期
		Warehouse:        in.Warehouse,                           // 仓库
		Preparer:         in.Preparer,                            // 制单人
		WarehouseManager: in.WarehouseManager,                    // 仓管员
		ReturnDept:       in.ReturnDept,                          // 退库科室
		Returner:         in.Returner,                            // 退库人
		Remarks:          in.Remarks,                             // 备注
		StatusID:         in.StatusID,                            // 状态ID
		ReturnStatus:     in.ReturnStatus,                        // 状态
		UpdatedAtuser:    in.UpdatedAtuser,                       // 更新用户
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
